<template>
  <div class="servicePackageList pd-20">
    <el-input v-model="searchCondition"
              placeholder="请选择服务包名称"
              class="w-200"
              clearable
              @clear="cleatTableData" />
    <el-select v-model="hospitalId"
               filterable
               remote
               reserve-keyword
               :remote-method="(query) => {remoteMethod1(query, 'searchName')}"
               :loading="loading1"
               class="w-200"
               clearable
               placeholder="请选择医院名称"
               @change="val=>handleSelect(val, 'searchName')"
               @clear="cleatTableData">
      <el-option v-for="item in options"
                 :value="item.id"
                 :label="item.name"
                 :key="item.id"></el-option>
    </el-select>
    <el-button type="primary"
               @click="initTableData">查 询</el-button>
    <el-button type="primary"
               @click="handleOption">新 增</el-button>
    <!--服务包列表-->
    <Table stripe
           border
           :columns="titles"
           :data="dataList"
           class="mt-20">
      <template slot-scope="{row,index}"
                slot="action">
        <span @click="handleOption(index)">编辑</span>
        <span @click="deleteServicePackage(index)">删除</span>
      </template>
    </Table>
    <!--分页-->
    <Page :current.sync="currentPage"
          :total="totals"
          :page-size="pageSize"
          @on-change="handleChange"
          show-total />
    <el-dialog :visible.sync="editServicePackage"
               :title="title"
               width="99%"
               @close="editServicePackage = false"
               center
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="servicePackage"
               ref="formRefs"
               inline="inline"
               :rules="formRules">
        <el-card>
          <span slot="header"
                class="base-info">基本信息</span>

          <el-form-item label="服务包名称："
                        prop="name">
            <el-input v-model="servicePackage.name"
                      placeholder="请填写服务包名称"
                      class="w-200"
                      clearable />
          </el-form-item>
          <el-form-item label="选择医院："
                        prop="hospitalId">
            <el-select v-model="servicePackage.hospitalId"
                       filterable
                       remote
                       :remote-method="(query) => {remoteMethod1(query, 'selectHospital')}"
                       reserve-keyword
                       @change="val=>handleSelect(val, 'selectHospital')"
                       :loading="loading2"
                       class="w-200"
                       clearable
                       placeholder="请选择医院">
              <el-option v-for="item in hospitalList"
                         :value="item.id"
                         :label="item.name"
                         :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择科室："
                        prop="departmentId">
            <el-select v-model="servicePackage.departmentId"
                       filterable
                       remote
                       :remote-method="initDepartment"
                       :loading="loading1"
                       class="w-200"
                       clearable
                       placeholder="请选择科室">
              <el-option v-for="item in departmentList"
                         :value="item.id"
                         :label="item.name"
                         :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择病种："
                        prop="diseaseId">
            <el-select v-model="servicePackage.diseaseId"
                       filterable
                       remote
                       @change="setServicePackageName"
                       :remote-method="initDisease"
                       :loading="loading1"
                       class="w-200"
                       clearable
                       placeholder="请选择病种">
              <el-option v-for="item in diseaseList"
                         :value="item.id"
                         :label="item.name"
                         :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择工作室："
                        prop="studioId">
            <el-select v-model="servicePackage.studioId"
                       filterable
                       remote
                       :remote-method="initWdStudio"
                       :loading="loading1"
                       class="w-200"
                       clearable
                       placeholder="请选择工作室">
              <el-option v-for="item in studioList"
                         :value="item.id"
                         :label="item.name"
                         :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="义工配置："
                        prop="volunteerId">
            <el-select v-model="servicePackage.volunteerId"
                       filterable
                       remote
                       :remote-method="initVolunteerList"
                       :loading="loading1"
                       class="w-200"
                       clearable
                       placeholder="请义工配置">
              <el-option v-for="item in volunteerList"
                         :value="item.id"
                         :label="item.name"
                         :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="每单推广费用："
                        prop="extendFee">
            <el-input v-model="servicePackage.extendFee"
                      placeholder="请填写推广费用"
                      class="w-200" />
          </el-form-item>
          <el-form-item label="慢病签约服务费标准：">
            <el-input v-model="servicePackage.cdpFee"
                      placeholder="请填写慢病服务费"
                      class="w-200" />
          </el-form-item>

          <el-form-item label="购买服务后，是否填写健康服务号："
                        prop="isInvitationCode">
            <el-radio-group v-model="servicePackage.isInvitationCode">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>

        </el-card>
        <el-card class="mt-20">
          <p>
            <span slot="header"
                  class="base-info">服务包规格配置</span>
            <el-button type="primary"
                       @click="addServiceItem">新 增</el-button>
          </p>
          <el-form-item prop="serviceItem">
            <el-table :data="servicePackage.serviceItem"
                      style="width: 100%"
                      border
                      class="mt-20">
              <el-table-column prop="name"
                               label="名称"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.name"
                                :prop="`serviceItem.${scope.$index}.name`">
                    <el-input v-model="scope.row.name"
                              placeholder="请输入名称"
                              class="w-200"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="discountPriceId"
                               label="服务包价格"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.discountPriceId"
                                :prop="`serviceItem.${scope.$index}.discountPriceId`">
                    <el-select v-model="scope.row.discountPriceId"
                               class="w-200"
                               clearable
                               placeholder="请选择服务包价格">
                      <el-option v-for="item in priceConfig"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="originalPriceId"
                               label="服务包原价"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.originalPriceId"
                                :prop="`serviceItem.${scope.$index}.originalPriceId`">
                    <el-select v-model="scope.row.originalPriceId"
                               class="w-200"
                               clearable
                               placeholder="请选择服务包原价">
                      <el-option v-for="item in priceConfig"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="effectiveMonth"
                               label="服务包月份数"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.effectiveMonth"
                                :prop="`serviceItem.${scope.$index}.effectiveMonth`">
                    <el-select v-model="scope.row.effectiveMonth"
                               class="w-200"
                               clearable
                               placeholder="请选择服务包月份数">
                      <el-option v-for="item in monthNumList"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="groupId"
                               label="分组"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.groupId"
                                :prop="`serviceItem.${scope.$index}.groupId`">
                    <el-select v-model="scope.row.groupId"
                               class="w-200"
                               clearable
                               placeholder="请选择分组">
                      <el-option v-for="item in groupList"
                                 :key="item.id"
                                 :label="item.groupName"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="giftId"
                               label="活动"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.giftId"
                                :prop="`serviceItem.${scope.$index}.giftId`">
                    <el-select v-model="
                                scope.row.giftId"
                               class="w-200"
                               clearable
                               placeholder="请选择活动">
                      <el-option v-for="item in giftList"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>

                </template>
              </el-table-column>
              <el-table-column prop="introduceId"
                               label="服务包介绍"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="listRules.introduceId"
                                :prop="`serviceItem.${scope.$index}.introduceId`">
                    <el-select v-model="scope.row.introduceId"
                               class="w-200"
                               clearable
                               placeholder="请选择服务包介绍">
                      <el-option v-for="item in introduceList"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="option"
                               label="操作"
                               width="100"
                               align="center">
                <template slot-scope="scope">
                  <el-button type="danger"
                             @click="removeServiceItemTitles(scope.$index)">删 除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>

        </el-card>
        <el-card class="mt-20">
          <p>
            <span slot="header"
                  class="base-info">服务医生配置</span>
            <el-button type="primary"
                       @click="addServiceDoctor">新 增</el-button>
          </p>
          <el-form-item prop="serviceDoctor">
            <el-table :data="servicePackage.serviceDoctor"
                      border
                      style="width: 100%"
                      class="mt-20">
              <el-table-column label="名称"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.name"
                                :prop="`serviceDoctor.${scope.$index}.name`">
                    <el-input v-model="scope.row.name"
                              class="w-200"
                              clearable
                              placeholder="请输入名称"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="doctorTitleIds"
                               label="职称"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.doctorTitleIds"
                                :prop="`serviceDoctor.${scope.$index}.doctorTitleIds`">
                    <el-select v-model="scope.row.doctorTitleIds"
                               class="w-200"
                               clearable
                               multiple
                               placeholder="请选择职称">
                      <el-option v-for="item in doctorTitles"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="groupId"
                               label="分组"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.groupId"
                                :prop="`serviceDoctor.${scope.$index}.groupId`">
                    <el-select v-model="scope.row.groupId"
                               class="w-200"
                               clearable
                               placeholder="请选择分组">
                      <el-option v-for="item in groupList"
                                 :key="item.id"
                                 :label="item.groupName"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="num"
                               label="服务人数"
                               width="150">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.num"
                                :prop="`serviceDoctor.${scope.$index}.num`">
                    <el-input v-model="scope.row.num"
                              class="w-100"
                              clearable
                              placeholder="服务人数"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="count"
                               label="每月服务次数"
                               width="150">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.count"
                                :prop="`serviceDoctor.${scope.$index}.count`">
                    <el-input v-model="scope.row.count"
                              class="w-100"
                              clearable
                              placeholder="服务次数"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="hospitalLevel"
                               label="医院等级"
                               width="240">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.hospitalLevels"
                                :prop="`serviceDoctor.${scope.$index}.hospitalLevels`">
                    <el-select v-model="scope.row.hospitalLevels"
                               class="w-200"
                               clearable
                               multiple
                               placeholder="请选择医院等级">
                      <el-option v-for="item in hospitalLevels"
                                 :key="item.id"
                                 :label="item.name"
                                 :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="relationship"
                               label="关系"
                               width="150">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.relationship"
                                :prop="`serviceDoctor.${scope.$index}.relationship`">
                    <el-select v-model="scope.row.relationship"
                               class="w-100"
                               clearable
                               placeholder="请选择关系">
                      <el-option v-for="item in relationships"
                                 :key="item.key"
                                 :label="item.value"
                                 :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="isRequired"
                               label="是否必须"
                               width="150">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.isRequired"
                                :prop="`serviceDoctor.${scope.$index}.isRequired`">
                    <el-select v-model="scope.row.isRequired"
                               class="w-100"
                               clearable
                               placeholder="请选择">
                      <el-option v-for="item in isRequireds"
                                 :key="item.key"
                                 :label="item.value"
                                 :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="serviceLevel"
                               label="服务级别"
                               width="150">
                <template slot-scope="scope">
                  <el-form-item :rules="doctorRules.serviceLevel"
                                :prop="`serviceDoctor.${scope.$index}.serviceLevel`">
                    <el-select v-model="scope.row.serviceLevel"
                               class="w-100"
                               clearable
                               placeholder="请选择服务级别">
                      <el-option v-for="item in serviceLevels"
                                 :key="item.key"
                                 :label="item.value"
                                 :value="item.key">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="option"
                               label="操作"
                               width="100">
                <template slot-scope="scope">
                  <el-button type="danger"
                             @click="removeServiceDoctorTitles(scope.$index)">删 除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>

        </el-card>
      </el-form>
      <p align="center"
         class="mt-20">
        <el-button @click="editServicePackage = false">取 消</el-button>
        <el-button type="primary"
                   @click="saveData">确 定</el-button>
      </p>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "servicePackageList",
    data () {
      return {
        title: '新 增',
        searchCondition: '',
        hospitalId: null,
        currentPage: 1,
        totals: 0,
        pageSize: 20,
        loading1: false,
        loading2: false,
        editServicePackage: false,
        loading: false,
        optionsAll: [],
        options: [],
        hospitalList: [],
        hospitalAllList: [],
        departmentList: [],
        studioList: [],
        diseaseList: [],
        doctorTitles: [],
        priceConfig: [],
        groupList: [],
        hospitalLevels: [],
        introduceList: [],
        giftList: [],
        isRequireds: [
          { key: 1, value: "必须" },
          { key: 0, value: "非必须" }
        ],
        serviceLevels: [
          { key: 1, value: "专家" },
          { key: 2, value: "医生" },
          { key: 3, value: "助理" },
          { key: 4, value: "社区义工" },
        ],
        relationships: [
          { key: ">", value: ">" },
          { key: ">=", value: ">=" },
          { key: "<", value: "<" },
          { key: "<=", value: "<=" },
          { key: "=", value: "=" }],
        monthNumList: [
          {
            id: 1,
            name: "1月"
          },
          {
            id: 2,
            name: "2月"
          },
          {
            id: 3,
            name: "3月"
          },
          {
            id: 4,
            name: "4月"
          },
          {
            id: 5,
            name: "5月"
          },
          {
            id: 6,
            name: "6月"
          },
          {
            id: 7,
            name: "7月"
          },
          {
            id: 8,
            name: "8月"
          },
          {
            id: 9,
            name: "9月"
          },
          {
            id: 10,
            name: "10月"
          },
          {
            id: 11,
            name: "11月"
          },
          {
            id: 12,
            name: "12月"
          }
        ],
        titles: [
          {
            title: '服务包名称',
            key: 'name'
          },
          {
            title: '医院名称',
            key: 'hospitalName'
          },
          {
            title: '科室',
            key: 'departmentName'
          },
          {
            title: '病种',
            key: 'diseaseName'
          },
          {
            title: '工作室',
            key: 'studioName'
          },
          {
            title: '创建时间',
            key: 'createTime',
            render: (h, params) => {
              return h('span',
                this.commonFunction.timestampFormat(new Date(params.row.createTime), 'yyyy-MM-dd hh:mm:ss'));
            }
          },
          {
            title: '操作',
            slot: 'action',
            align: 'center',
            width: 150
          }
        ],

        dataList: [],
        volunteerList: [],
        servicePackage: {
          name: "",
          hospitalId: null,
          hospitalName: "",
          departmentId: null, // 科室
          diseaseName: "",
          departmentName: "",
          diseaseId: null, // 病种
          studioId: null, // 工作室
          studioName: "",
          volunteerId: null, // 义工
          volunteer: null,
          isInvitationCode: 0, // 购买服务后，是否填写健康服务号
          serviceDoctor: [], // 服务医生配置
          serviceItem: [], // 服务包规格配置
          cdpFee:'' // 服务包规格配置
        },
        formRules: {
          name: [{ required: true, message: '请填写服务包名称', trigger: 'blur' }],
          hospitalId: [{ required: true, message: '请选择医院', trigger: 'change' }],
          departmentId: [{ required: true, message: '请选择科室', trigger: 'change' }],
          diseaseId: [{ required: true, message: '请选择病种', trigger: 'change' }],
          studioId: [{ required: true, message: '请选择工作室', trigger: 'change' }],
          serviceItem: [{ required: true, message: '请配置服务包规格', trigger: 'change' }],
          serviceDoctor: [{ required: true, message: '请配置服务医生', trigger: 'change' }],
        },
        listRules: {
          name: [{ required: true, message: '请输入名称', trigger: ['blur', 'change'] }],
          discountPriceId: [{ required: true, message: '请选择服务包价格', trigger: ['blur', 'change'] }],
          originalPriceId: [{ required: false, message: '请选择服务包原价', trigger: ['blur', 'change'] }],
          effectiveMonth: [{ required: false, message: '请选择服务包月份数', trigger: ['blur', 'change'] }],
          groupId: [{ required: false, message: '请选择分组', trigger: ['blur', 'change'] }],
          giftId: [{ required: false, message: '请选择活动', trigger: ['blur', 'change'] }],
          introduceId: [{ required: false, message: '请选择服务包介绍', trigger: ['blur', 'change'] }],
        },
        doctorRules: {
          name: [{ required: true, message: '请输入名称', trigger: ['blur', 'change'] }],
          doctorTitleIds: [{ required: true, message: '请选择职称', trigger: ['blur', 'change'] }],
          groupId: [{ required: false, message: '请选择分组', trigger: ['blur', 'change'] }],
          num: [{ required: true, message: '请输入服务人数', trigger: ['blur', 'change'] }],
          count: [{ required: false, message: '请输入服务次数', trigger: ['blur', 'change'] }],
          hospitalLevels: [{ required: false, message: '请选择医院等级', trigger: ['blur', 'change'] }],
          relationship: [{ required: false, message: '请选择关系', trigger: ['blur', 'change'] }],
          isRequired: [{ required: true, message: '请选择', trigger: ['blur', 'change'] }],
          serviceLevel: [{ required: false, message: '请选择服务级别', trigger: ['blur', 'change'] }],
        }
      }
    },
    created () {
      this.initTableData();
      this.initDoctorTitles();
      this.initPrices(); // 服务包价格
      this.initGroupList(); // 分组
      this.initHospitalLevels();
      this.initGiftList('');
      this.initVolunteerList('');
      this.initIntroduceList("");
    },
    methods: {
      cleatTableData () {
        this.currentPage = 1;
        this.initTableData();
      },
      initTableData () {
        let param = {
          name: this.searchCondition,
          hospitalId: this.hospitalId,
          pageSize: this.pageSize,
          pageIndex: this.currentPage - 1
        };
        this.post(this.api.servicePackage.getAllPackage, param).then((res) => {
          if (res.data.code === '200') {
            this.dataList = res.data.object;
            this.totals = res.data.totalNum;
          }
        });
      },
      // 职称
      initDoctorTitles () {
        this.post(this.api.doctorTitle.getPageAPP, { "pageIndex": 0, "pageSize": 100 }).then((res) => {
          if (res.data.code === '200') {
            this.doctorTitles = res.data.object;
          }
        });
      },
      initIntroduceList (obj) {
        let param = {
          "name": obj,
          "pageIndex": 0,
          "pageSize": 100
        };
        this.post(this.api.servicePackage.getServicePackageIntroduceList, param).then((res) => {
          if (res.data.code === '200') {
            this.introduceList = res.data.object;
          }
        });
      },
      initPrices () {
        let param = {
          "pageIndex": 0,
          "pageSize": 100
        };
        this.post(this.api.servicePackage.getConfigPrice, param).then((res) => {
          if (res.data.code === '200') {
            this.priceConfig = res.data.object;
          }
        });
      },
      initGiftList (name) {
        let param = {
          "name": name,
          "pageIndex": 0,
          "pageSize": 100
        };
        this.post(this.api.serviceGiftList.url, param).then((res) => {
          if (res.data.code === '200') {
            this.giftList = res.data.object;
          }
        });
      },
      // 分组
      initGroupList () {
        let param = {
          hospitalId: this.servicePackage.hospitalId,
          departmentId: this.servicePackage.departmentId,
          diseaseId: this.servicePackage.diseaseId,
          studioId: this.servicePackage.studioId
        };
        this.post(this.api.servicePackage.getServicePackageGroup, param).then((res) => {
          if (res.data.code === '200') {
            this.groupList = res.data.object;
          }
        });
      },
      initHospitalLevels () {
        this.post(this.api.hospitalLevel.getHospitalLevel, {}).then((res) => {
          if (res.data.code === '200') {
            this.hospitalLevels = res.data.object;
          }
        });
      },
      handleChange (page) {
        let _start = (page - 1) * this.pageSize;
        let _end = page * this.pageSize;
        this.initTableData()
      },
      handleOption (obj) {
        let _this = this;
        _this.editServicePackage = true;
        if (!isNaN(obj)) {
          _this.title = '编 辑';
          let id = this.dataList[obj].id;
          this.post(this.api.servicePackage.getServicePackageDetail, { "id": id }).then((res) => {
            if (res.data.code === '200') {
              _this.servicePackage = res.data.object;
              if (_this.servicePackage.volunteer == 1) {
                _this.servicePackage.volunteer = true;
              } else {
                _this.servicePackage.volunteer = false;
              }
              _this.hospitalList = [{ "id": this.servicePackage.hospitalId, "name": this.servicePackage.hospitalName }];
              _this.diseaseList = [{ "id": this.servicePackage.diseaseId, "name": this.servicePackage.diseaseName }];
              _this.departmentList = [{
                "id": _this.servicePackage.departmentId,
                "name": _this.servicePackage.departmentName
              }];
              if (_this.servicePackage.studioId) {
                _this.studioList = [{ "id": _this.servicePackage.studioId, "name": _this.servicePackage.studioName }];
              }

            }
          });
        } else {
          _this.title = '新 增';
          console.log(this.$refs);
          // this.$nextTick(() => {
          //   this.$refs.formRefs.resetFields();
          // })
          // 新增时清空上一次留下来的数据
          this.servicePackage = {
            name: "",
            hospitalId: null,
            hospitalName: "",
            departmentId: null, // 科室
            diseaseName: "",
            departmentName: "",
            diseaseId: null, // 病种
            studioId: null, // 工作室
            studioName: "",
            volunteerId: null, // 义工
            volunteer: null,
            isInvitationCode: 0, // 购买服务后，是否填写健康服务号
            serviceDoctor: [], // 服务医生配置
            serviceItem: [] // 服务包规格配置
          }
        }
      },
      saveData () {
        if (this.servicePackage.volunteer) {
          this.servicePackage.volunteer = 1;
        } else {
          this.servicePackage.volunteer = 0;
        }
        if (this.servicePackage.extendFee == 0) {
          this.servicePackage.extendFee = undefined;
        }
        if ((this.servicePackage.extendFee && this.servicePackage.extendFee.toString().split(".")[1] && this.servicePackage.extendFee.toString().split(".")[1].length > 2)) {
          this.$message.warning('每单推广费用大于0且至多两位小数')
          return
        }
        if (this.servicePackage.extendFee) {
          this.servicePackage.way = 1;
        } else {
          this.servicePackage.way = null;
        }
        this.$refs.formRefs.validate((valid) => {
          if (valid) {
            this.post(this.api.servicePackage.uploadInfo, this.servicePackage).then((res) => {
              let result = res.data;
              if (result.code === '200') {
                this.loading = false;
                this.$message.success("保存成功");
                this.editServicePackage = false;
                this.initTableData();
              }
            });
          }
        })

      },
      // 远程搜索医院
      remoteMethod1 (query, type) {
        if (query !== '') {
          let _this = this;
          if (type === 'searchName') {
            _this.loading1 = true;
          }
          if (type === 'selectHospital') {
            _this.loading2 = true;
          }
          this.post(this.api.searchHospital, { "pageSize": 20, "pageStart": 0, "name": query }).then((res) => {
            if (res.data.code === '200') {
              if (type === 'searchName') {
                _this.loading1 = false;
                _this.optionsAll = res.data.object;
              }
              if (type === 'selectHospital') {
                _this.loading2 = false;
                _this.hospitalListAll = res.data.object;
              }
            }
          });
          setTimeout(() => {
            if (type === 'searchName') {
              _this.loading1 = false;
              _this.options = _this.optionsAll.filter(item => item.name.indexOf(query) > -1);
            }
            if (type === 'selectHospital') {
              _this.loading2 = false;
              _this.hospitalList = _this.hospitalListAll.filter(item => item.name.indexOf(query) > -1);
            }
          }, 200);
        } else {
          if (type === 'searchName') {
            this.options = [];
          }
          if (type === 'selectHospital') {
            this.hospitalList = [];
          }
        }
      },
      handleSelect (val, type) {
        console.log(type)
        if (type === 'selectHospital') {
          this.initDepartment(val, null); // 科室
        }
      },
      initDepartment (val) {
        if (!this.servicePackage.hospitalId) {
          this.$message.error('请先选择医院');
          return;
        }
        let param = {
          hospitalId: this.servicePackage.hospitalId,
          name: val
        };
        // 科室
        this.post(this.api.department.getDepartmentPageAPP, param).then((res) => {
          if (res.data.code === '200') {
            this.departmentList = res.data.object;
            this.initDisease();
          }
        });
      },
      initVolunteerList (obj) {
        let param = {
          name: obj,
          pageIndex: 0,
          pageSize: 50
        };
        this.post(this.api.volunteer.getPageApp, param).then((res) => {
          if (res.data.code === '200') {
            this.volunteerList = res.data.object;
          }
        });
      },
      // 工作室
      initWdStudio (obj) {
        if (!this.servicePackage.hospitalId) {
          this.$message.error('请先选择医院');
          return;
        }
        let param = {
          hospitalId: this.servicePackage.hospitalId,
          searchCondition: obj
        };
        this.post(this.api.wdStudio.getHospitalStudio, param).then((res) => {
          if (res.data.code === '200') {
            this.studioList = res.data.object;
          }
        });
      },
      initDisease (obj) {
        if (!this.servicePackage.hospitalId) {
          this.$message.error('请先选择医院');
          return;
        }
        let param = {
          hospitalId: this.servicePackage.hospitalId,
          searchCondition: obj,
          pageIndex: 0,
          pageSize: 200
        };
        this.post(this.api.disease.searchHospitalDisease, param).then((res) => {
          if (res.data.code === '200') {
            this.diseaseList = res.data.object;
            this.initWdStudio();
          }
        });
      },
      setServicePackageName (obj) {
        // this.initGroupList();
        if (this.diseaseList && this.diseaseList.length > 0) {
          for (let i = 0; i < this.diseaseList.length; i++) {
            let disease = this.diseaseList[i];
            if (disease.id === obj) {
              this.servicePackage.name = disease.name + "服务包";
            }
          }
        }
      },
      addServiceItem () {
        let param = {
          name: null,
          discountPriceId: null, // 服务包价格
          originalPriceId: null, // 服务包原价
          effectiveMonth: null, // 服务包月份数
          groupId: null, // 分组
          giftId: null, // 活动
          introduceId: null, // 服务包介绍
        };
        this.servicePackage.serviceItem.push(param);
      },
      addServiceDoctor () {
        let param = {
          name: '',
          doctorTitleIds: [], // 职称
          groupId: '',
          num: '',
          count: '',
          hospitalLevels: [], // 医院等级
          relationship: '',
          isRequired: '',
          serviceLevel: '',
        };
        this.servicePackage.serviceDoctor.push(param);
      },
      removeServiceItemTitles (id) {
        let newData = [];
        for (let i = 0; i < this.servicePackage.serviceItem.length; i++) {
          if (id === i) {
            continue;
          }
          newData.push(this.servicePackage.serviceItem[i]);
        }
        this.servicePackage.serviceItem = newData;
      },
      removeServiceDoctorTitles (id) {
        let newData = [];
        for (let i = 0; i < this.servicePackage.serviceDoctor.length; i++) {
          if (id === i) {
            continue;
          }
          newData.push(this.servicePackage.serviceDoctor[i]);
        }
        this.servicePackage.serviceDoctor = newData;
      },
      deleteServicePackage (index) {
        let obj = this.dataList[index];
        if (obj) {
          this.$confirm('确认删除？')
            .then(_ => {
              this.post(this.api.servicePackage.deleteServicePackage, { "id": obj.id }).then((res) => {
                if (res.data.code === '200') {
                  this.$message.success("删除成功");
                  this.initTableData();
                }
              });
            })
            .catch(_ => { });
        }
      },
    }
  }
</script>
<style scoped lang="scss">
  .base-info {
    font-size: 14px;
    font-weight: bold;
  }
  .w-100 {
    width: 100px;
  }
</style>
